package com.cn.gxa.springjpa.controller;

import com.cn.gxa.springjpa.bean.User;
import com.cn.gxa.springjpa.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserController {
    @Resource
    private UserService  userService;

    @GetMapping("/findAll")
    public List<User> findAll(){
        return   userService.findAll();
    }

    @GetMapping("/findById/{id}")
    public User findById(@PathVariable("id") Integer  id){
        User  user=userService.findById(id);
        System.out.println(user+"==========================");
        //session
        return   user;
    }

    @GetMapping("/findByName")
    public List<User> findByName(String  name){
        return   userService.findByName(name);
    }

    @GetMapping("/findAllOderBy")
    public List<User> findAllOderBy(){
        return   userService.findAllOderBy();
    }


    @GetMapping("/updateUserAuth")
    public String updateUserAuth(String  auth,Integer no){
          userService.updateUserAuth(auth,no);
        return "success";
    }

}
